<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="news.bll.topic.*"%>
<%@ page import="news.entity.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'do_modifytopic.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    request.setCharacterEncoding("utf-8");
	int tid = Integer.parseInt(request.getParameter("tid"));
	String newtname=request.getParameter("tname");
	TopicDaoImpl tdi = new TopicDaoImpl();
	List<Topic> topics = tdi.getAllTopics();
	List<String> tnames = new ArrayList<String>();
	for(int i = 0; i<topics.size(); i++){
		tnames.add(topics.get(i).getTname());
	}
	if(!tnames.contains(newtname)){
		int result = tdi.modifyTopic(tid, newtname);
		if(result>0){
			%>
			<script>
				alert("主题修改成功！");
				window.location="admin.jsp";
			</script>    		
			<%
		}else{
			%>
			<script>
				alert("主题修改失败！");
				window.location="topic_modify.jsp";
			</script>    		
			<%
		}
	}else{
		%>
   		<script>
   			alert("当前主题已存在，请重新输入不同的主题！");
   			window.location="topic_add.jsp";
   		</script>    		
   		<%
	}
	%>
	
  </body>
</html>
